﻿using M_Process.API.Appliction.Command.ProductionProcessCommand;
using M_Process.Domain;
using M_Process.Repository.ProcessInterface;
using MediatR;

namespace M_Process.API.Appliction.CommandHandlers.ProductionProcessCommandHandler
{
    /// <summary>
    /// 创建工序命令处理器
    /// </summary>
    public class CreadProductionProcessCommandHandler : IRequestHandler<CreadProductionProcessCommand, int>
    {
        /// <summary>
        /// 工序仓储接口
        /// </summary>
        protected readonly IProductionProcessRepository productionProcessRepository;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="productionProcessRepository">工序仓储接口</param>
        public CreadProductionProcessCommandHandler(IProductionProcessRepository productionProcessRepository)
        {
            this.productionProcessRepository = productionProcessRepository;
        }

        /// <summary>
        /// 处理创建工序命令
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<int> Handle(CreadProductionProcessCommand request, CancellationToken cancellationToken)
        {
            return await productionProcessRepository.AddAsync(new ProductionProcess()
            {
                ProductionProcessesName = request.ProductionProcessesName,
                ProductionProcessesNumber = request.ProductionProcessesNumber,
                Specification = request.Specification,
                Status = request.Status,
                ProcessClassification=request.ProcessClassification,
                Notes = request.Notes,
                CreatedBy = request.CreatedBy,
                CreatedDate = DateTime.Now
            });
        }
    }
}
